package com.andaily.web.controller.mobile.account;

import com.andaily.domain.dto.account.AccountDTO;
import com.andaily.domain.dto.account.AccountOverviewDTO;
import com.andaily.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    private AccountService accountService;

    @RequestMapping("overview")
    public String overview(AccountOverviewDTO accountOverviewDTO, ModelMap model) throws Exception {
        accountOverviewDTO = accountService.loadAccountOverview(accountOverviewDTO);
        model.put("accountOverview", accountOverviewDTO);
        return "account/account_overview";
    }

    @RequestMapping("details/{guid}")
    public String details(@PathVariable() String guid, ModelMap model) throws Exception {
        AccountDTO accountDTO = accountService.loadByGuid(guid);
        model.addAttribute("account", accountDTO);
        return "account/account_details";
    }

    @RequestMapping("more")
    public String more(AccountOverviewDTO accountOverviewDTO, ModelMap model) throws Exception {
        accountOverviewDTO = accountService.loadAccountOverview(accountOverviewDTO);
        model.put("accountOverview", accountOverviewDTO);
        return "account/account_overview_more";
    }

    @RequestMapping("delete_confirm/{guid}")
    public String deleteConfirm(@PathVariable() String guid, ModelMap model) throws Exception {
        model.addAttribute("account_guid", guid);
        return "account/account_delete_confirm";
    }

    @RequestMapping("delete/{guid}")
    public String delete(@PathVariable() String guid) throws Exception {
        accountService.archivedAccount(guid);
        return "redirect:/m/account/overview";
    }

    @Autowired
    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }
}
